#!/usr/bin/env python
# coding=utf-8

from vavava.workqueue import Work
from . import fetcher_dhl
from .. import taskworkbase

class DhlWork(Work):
    def __init__( self, item_id, group, proxy=None, begin_time=None, period=None, log=None ):
        Work.__init__( self, period=period, group=group,
            begin_time=begin_time, log=log, name="[DhlWork|%s]" % item_id )
        self.fetcher_ = fetcher_dhl.fetcher_dhl ( item_id=item_id, log=log )
        self.proxy_  = proxy

    def do(self,worker=None):
        self.fetcher_.SetDBConn(self._work_param)
        self.fetcher_.SetProxy(self.proxy_)
        self.fetcher_.Fetch()

    def __hash__(self):
        return hash(self.fetcher_.item_id)

class DhlTaskWork(taskworkbase.TaskWorkBase):
    def __init__( self, period, group, begin_time=None, log=None, **kvarg ):
        taskworkbase.TaskWorkBase.__init__(
            self,track_type=2,period=period,group=group,begin_time=begin_time,log=log )

    def _get_all_items(self):
        return ["8253917394"]

    def _get_work_instance(self, item_id):
        return DhlWork(
            item_id=item_id,
            group=self.group_id,
            proxy=self.proxy_,
            begin_time=None,
            period=None,
            log=self.log
        )


